package com.zrwl.poscloud.core.restapi.admin.baseInfo;

import com.zrwl.poscloud.core.annotion.AuthorityVerify.AuthorityVerify;
import com.zrwl.poscloud.core.annotion.OperationLogger.OperationLogger;
import com.zrwl.poscloud.commons.exception.ThrowableUtils;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.validator.group.Delete;
import com.zrwl.poscloud.commons.validator.group.GetList;
import com.zrwl.poscloud.commons.validator.group.Insert;
import com.zrwl.poscloud.commons.validator.group.Update;
import com.zrwl.poscloud.xo.service.MessageSmsService;
import com.zrwl.poscloud.xo.vo.MessageSmsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * 短信 controller api类
 *
 * @author 刘思童 AutoGenerate
 * @date 2022-09-08
 */
@RestController
@Api(value = "短信相关接口", tags = {"短信相关接口"})
@RequestMapping("/messageSms")
@Slf4j
public class MessageSmsRestApi {
    @Autowired
    private MessageSmsService messageSmsService;
    @AuthorityVerify
    @ApiOperation(value = "获取短信列表", notes = "获取短信列表", response = String.class)
    @PostMapping("/getList")
    public String getList(@Validated({GetList.class}) @RequestBody MessageSmsVO messageSmsVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取短信列表: {}", messageSmsVO);
        return ResultUtil.successWithData(messageSmsService.getPageList(messageSmsVO));
    }

    @AuthorityVerify
    @ApiOperation(value = "获取短信列表", notes = "获取短信列表", response = String.class)
    @PostMapping("/getAllList")
    public String getAllList(@Validated({GetList.class}) @RequestBody MessageSmsVO messageSmsVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取短信列表: {}", messageSmsVO);
        return ResultUtil.successWithData(messageSmsService.getAllList(messageSmsVO));
    }

    @AuthorityVerify
    @OperationLogger(value = "新增短信")    @ApiOperation(value = "新增短信", notes = "新增短信", response = String.class)
    @PostMapping("/add")
    public String add(@Validated({Insert.class}) @RequestBody MessageSmsVO messageSmsVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("新增短信: {}", messageSmsVO);
        return messageSmsService.add(messageSmsVO);
    }
    @AuthorityVerify
    @OperationLogger(value = "发送新增短信消息")    @ApiOperation(value = "发送新增短信消息", notes = "发送新增短信消息", response = String.class)
    @PostMapping("/addSend")
    public String addSend(@Validated({Insert.class}) @RequestBody MessageSmsVO messageSmsVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("发送新增短信消息: {}", messageSmsVO);
        return messageSmsService.addSend(messageSmsVO);
    }
    @AuthorityVerify
    @OperationLogger(value = "重新发送短信消息")    @ApiOperation(value = "重新发送短信消息", notes = "重新发送短信消息", response = String.class)
    @PostMapping("/resend")
    public String resendMessage(@Validated({Insert.class}) @RequestBody MessageSmsVO messageSmsVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("重新发送短信消息: {}", messageSmsVO);
        String sendAMessage = messageSmsService.resendMessage(messageSmsVO);
        if (sendAMessage.contains("true")) {
            return ResultUtil.successWithMessage("发送成功");
        }
        return ResultUtil.errorWithMessage("发送失败");
    }
    @AuthorityVerify
    @OperationLogger(value = "发送短信")    @ApiOperation(value = "发送短信", notes = "发送短信", response = String.class)
    @PostMapping("/send")
    public String send(@Validated({Update.class}) @RequestBody MessageSmsVO messageSmsVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("发送短信消息: {}", messageSmsVO);
        String sendAMessage = messageSmsService.sendMessage(messageSmsVO);
        if (sendAMessage.contains("true")) {
            return ResultUtil.successWithMessage("发送成功");
        }
        return ResultUtil.errorWithMessage("发送失败");
    }
    @AuthorityVerify
    @OperationLogger(value = "修改短信")    @ApiOperation(value = "修改短信", notes = "修改短信", response = String.class)
    @PostMapping("/edit")
    public String edit(@Validated({Update.class}) @RequestBody MessageSmsVO messageSmsVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("修改短信: {}", messageSmsVO);
        return messageSmsService.edit(messageSmsVO);
    }

    @AuthorityVerify
    @OperationLogger(value = "删除短信")    @ApiOperation(value = "删除短信", notes = "删除短信", response = String.class)
    @PostMapping("/delete")
    public String delete(@Validated({Delete.class}) @RequestBody MessageSmsVO messageSmsVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("删除短信: {}", messageSmsVO);
        return messageSmsService.delete(messageSmsVO);
    }

}
